package com.modelo.dao.obraproveedor;

import java.util.List;

import org.hibernate.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Repository;

import com.modelo.dao.comun.HibernateBaseDAO;
import com.modelo.entity.ObraProveedor;

@Repository
public class ObraProveedorDAO extends HibernateBaseDAO<ObraProveedor> implements IObraProveedorDAO {
	private static final Logger log = LoggerFactory.getLogger(ObraProveedorDAO.class);

	public static ObraProveedorDAO getFromApplicationContext(ApplicationContext ctx) {
		return (ObraProveedorDAO) ctx.getBean("ObraProveedorDAO");
	}

	@Autowired
	public ObraProveedorDAO(SessionFactory sessionFactory) {
		super(sessionFactory);
	}

	public List<ObraProveedor> findByExample(ObraProveedor instance) {
		log.debug("finding ObraProveedor instance by example");
		try {
			List<ObraProveedor> results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: " + results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding ObraProveedor instance with property: " + propertyName + ", value: "
				+ value);
		try {
			String queryString = "from ObraProveedor as model where model." + propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	@Override
	protected void initDao() {

	}
}